from daos import get_db_session, get_update_contents
from models.album_record_info import AlbumRecordInfo


def add_album_record_info(model_orm: AlbumRecordInfo, is_commit=True):
    session = get_db_session()

    session.add(model_orm)
    session.commit() if is_commit else session.flush()
    return model_orm


def query_album_record_info(pk):
    return get_db_session().query(AlbumRecordInfo).filter(AlbumRecordInfo.id == pk).first()


def query_album_record_info_by_album_info_id(album_info_id):
    return get_db_session().query(AlbumRecordInfo).filter(AlbumRecordInfo.album_info_id == album_info_id).first()


def update_album_record_info(model_orm: AlbumRecordInfo, *args, is_commit=True):
    session = get_db_session()
    update_contents = get_update_contents(model_orm, *args)
    session.query(AlbumRecordInfo).filter(AlbumRecordInfo.id == model_orm.id).update(update_contents)
    session.commit() if is_commit else session.flush()
    return


def delete_album_record_info(pk, is_commit=True):
    session = get_db_session()
    session.query(AlbumRecordInfo).filter(AlbumRecordInfo.id == pk).delete()
    session.commit() if is_commit else session.flush()
    return


def delete_album_record_info_by_album_info_id(album_info_id, is_commit=True):
    session = get_db_session()
    session.query(AlbumRecordInfo).filter(AlbumRecordInfo.album_info_id == album_info_id).delete()
    session.commit() if is_commit else session.flush()
    return
